<?php
if(!$login_do) include("config.php");
if($_POST['session_id']){
	//////////////////////////////////////////////////////////////////////////////////////
	//获取姓名学号
	$snoopy1 = new Snoopy;
	//模拟HEADER
	$snoopy1->cookies['ASP.NET_SessionId'] = $_SESSION["ASP_NET_SessionId"];
	//获取分析表单
	$snoopy1->fetch($scoreurl);
	$res1 = $snoopy1->results;

	//超时返回
	if ($snoopy1->status != '200' || $snoopy1->timed_out) {
    	echo json_err(1,"页面获取超时！");
    	return;
	}

	$res1_html = new simple_html_dom();
	$res1_html->load($res1);
	$res1_tables  = $res1_html->find('table.GridViewStyle');
	
	$info_data    = [];
	$info_title   = [];
	foreach ($res1_tables as $table_key => $table) {
		$res1_trs     = $table->find('tr');
		foreach ($res1_trs as $key => $value){
			$res1_tds = $value->find('td');
			if($key==0 && count($info_title)==0)
				$info_title = [
					trim(strip_tags($res1_tds[0]->innertext)),
					trim(strip_tags($res1_tds[1]->innertext)),
					trim(strip_tags($res1_tds[2]->innertext)),
					trim(strip_tags($res1_tds[3]->innertext)),
					"课程类型"
				];
			else
				$info_data[] = [
					trim(strip_tags($res1_tds[0]->innertext)),
					trim(strip_tags($res1_tds[1]->innertext)),
					trim(strip_tags($res1_tds[2]->innertext)),
					trim(strip_tags($res1_tds[3]->innertext)),
					$table_key==0?"学位课程":"选修课程"
				];
		}
	}
	$score = ["title"=>$info_title,"data"=>$info_data];

	$res1_html->clear();

	//////////////////////////////////////////////////////////////////////////////////////
	//noapi调用
	if($_POST['noapi']){
		//echo "姓名：".$xm."    学号：".$xh;
		echo json_encode($score);
		return;
	}
	echo json_encode($score);
	return;

}else{
	echo json_err(2,'提交数据不全!');
	return;
}
?>